﻿<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String contextPath = request.getContextPath();
%>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/easyUI/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/easyUI/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=contextPath%>/resources/query-form.css">
	<%--<link href="<%=contextPath%>/resources/jquery.loadmask.css" rel="stylesheet" type="text/css"/>--%>

	<script type="text/javascript" src="<%=contextPath%>/resources/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="<%=contextPath%>/resources/easyUI/jquery.easyui.min.js"></script>
	<%--<script type="text/javascript" src="<%=contextPath%>/resources/easyUI/easyui-lang-zh_CN.js"></script>--%>
	<%--<script type="text/javascript" src="<%=contextPath%>/resources/js/views/defineTable.js"></script>--%>
	<%--<script type="text/javascript" src="<%=contextPath%>/resources/js/ExportExcelDlg.js"></script>--%>


	<script type="text/javascript">
	// 导入Excel
	function importExcel() {
		var fileObj = document.getElementById("expFiles").files[0]; // js 获取文件对象
		if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
			alert("请选择文件");
			return;
		}
		var formFile = new FormData();
		formFile.append("file", fileObj); //加入文件对象
		formFile.append("formsid", $('#formsid').combobox('getValue'));
//        formFile.append("year", 2015);
//        formFile.append("departid", 104);

		// /** 第一种  XMLHttpRequest 对象 */
		// var xhr = new XMLHttpRequest();
		// xhr.open("post", "/import/sync/excel.do", true);
		// xhr.onload = function () {
		//    // alert("上传完成!");
		// };
		// xhr.send(formFile);

		/** 第二种 ajax 提交 */
		$.ajax({
			url: "/import/sync/excel/user.do",
			data: formFile,
			type: "post",
			dataType: "json",
			cache: false,//上传文件无需缓存
			processData: false,//用于对data参数进行序列化处理 这里必须false
			contentType: false, //必须
			// beforeSend: function(){
			// //	上传前做的判断等
			// },
			success: function (result) {
				// 导入失败
				if(result.code!=200) {
					alert("导入失败!"+result.massage);
					return;
				}
				// 部分成功
				if(result["data"].size>0){

					var fail = result["data"].results;
					var one
					var failInfo
					for (var i = 0; i < result["data"].size; i++){
						one= fail[i];
						failInfo=one["error"]+one["value"]+" \n ";
					}
					alert("部分导入失败!"+" \n "+failInfo);
					return;
				}
				alert("成功导入!");
			}
		});
	}
	</script>

	<style>
		.time{
			/*text-align: center;    margin-top: 8%;*/
			/*position: relative;*/
		}
		.time ul{
			width: 380px;
			height: 200px;
			text-align: left;
			margin: auto;
			border: 1px solid #b9b6b6;
			padding: 20px;
			/*border-radius: 0px 0px 4px 4px;*/
		}
		.time_title{
			width: 400px;
			text-align: left;
			margin: auto;
			border: 1px solid #ccc;
			padding: 10px 10px;
			font-size: 16px;
			border-radius: 4px 4px 0px 0px;
			background-color: #ccc;
		}
	</style>
</head>
<body>
<div id="content" style="height: 100%">
	<div class="time">

		<%--<form name="catForm" enctype="multipart/form-data" >--%>
			<div class="time_title">批量导入</div>
			<ul>

				<li style="float:left; margin-left: 2%; margin-bottom: 30px;">
					<a href="<%=contextPath%>/resources/word/import.xlsx" target="_blank"
					   class="easyui-linkbutton" iconCls="icon-excel">下载导入模板</a>
					<div style=" background-color: #0d99a5" >注意：模板中的备注，请控制在30汉字以内。</div>
				</li>

				<li>
					<select class="easyui-combobox" name="formsid" id="formsid" style="width:190px; margin-bottom: 20px;">
						<c:forEach var="formOption" items="${formes}">
							<option value="${formOption.id}">${formOption.name}</option>
						</c:forEach>
					</select>
				</li>

				<li style="float:left; margin-left:1%; width:380px;">
					<input type="file" style=" width:180px; " name="expFiles" id="expFiles">
					<a href="javaScript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onclick="importExcel();" >导入数据</a>
				</li>
			</ul>
		<%--</form>--%>
	</div>

	<%--<iframe name="upload_back" style="display:none" id="upload_back"></iframe>--%>

</div>
</body>
</html>